package com.dm.cloud.images.service.impl;

import com.dm.cloud.tkmybatis.service.BaseMapper;
import com.dm.cloud.images.mapper.ImagesAppTaskMapper;
import com.dm.cloud.images.service.ImagesAppTaskService;
import com.dm.cloud.images.common.po.ImagesAppTask;
import com.dm.cloud.core.exception.CustomException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
   * @author hcx
   * @type ImagesAppTaskServiceImpl.java
   * @desc ImagesAppTask serviceImpl
   */
@Service

@Transactional

public class ImagesAppTaskServiceImpl implements ImagesAppTaskService {


    @Autowired
    private ImagesAppTaskMapper imagesAppTaskMapper;


    @Override
    public BaseMapper getMapper() {
        return imagesAppTaskMapper;
    }
    public void processBeforeOperation(ImagesAppTask entity, BaseOperationEnum operationEnum) throws CustomException {
    }

    public void processAfterOperation(ImagesAppTask entity, BaseOperationEnum operationEnum) throws CustomException {
    }

    @Override
    public ImagesAppTask findByAppCode(String appCode) {
        ImagesAppTask task= imagesAppTaskMapper.findByAppCode(appCode);
        return task;
    }

    /**
     * 当正在任务数小于lt时，返回一个未执行的任务
     * @param lt
     * @return
     */
    @Override
    public ImagesAppTask findNoStartLimit1ByRunLt(int lt) {
        int runSize=imagesAppTaskMapper.findRunTaskSize();
        if(runSize<lt){
            return imagesAppTaskMapper.findNoStartLimit1();
        }
        return null;
    }

    @Override
    public List<ImagesAppTask> findByServiceId(String serviceId) {
        return imagesAppTaskMapper.findByServiceId(serviceId);
    }

    @Override
    public int updateTaskParamById(int status, int tp, String serviceId,String id) {

        return imagesAppTaskMapper.updateTaskParamById(status,tp,serviceId,id);
    }

}
